package com.common.dao.hibernate.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Filter;
import org.hibernate.LockMode;
import org.hibernate.ReplicationMode;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.common.dao.hibernate.IBaseHibernateDao;

@Component("baseHibernateDao")
@Scope("singleton")
@Transactional(readOnly = false)
public class BaseHibernateDao implements IBaseHibernateDao {

	@Resource
	private HibernateTemplate hibernateTemplate = null;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackForClassName = { "DataAccessException" })
	public void executeByTransaction(Object[] entitys)
			throws DataAccessException {
		for (Object entity : entitys) {
			hibernateTemplate.save(entity);
			hibernateTemplate.flush();
			hibernateTemplate.clear();
		}
	}

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackForClassName = { "DataAccessException" })
	public Serializable save(Object entity) throws DataAccessException {
		return hibernateTemplate.save(entity);
	}

	public Serializable save(String entityName, Object entity)
			throws DataAccessException {
		return hibernateTemplate.save(entityName, entity);
	}

	public void saveOrUpdate(Object entity) throws DataAccessException {
		hibernateTemplate.saveOrUpdate(entity);
	}

	public void saveOrUpdate(String entityName, Object entity)
			throws DataAccessException {
		hibernateTemplate.saveOrUpdate(entityName, entity);
	}

	@SuppressWarnings("unchecked")
	public void saveOrUpdateAll(Collection entities) throws DataAccessException {
		hibernateTemplate.saveOrUpdateAll(entities);
	}

	public void update(Object entity) throws DataAccessException {
		hibernateTemplate.update(entity);
	}

	public void update(Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.update(entity, lockMode);
	}

	public void update(String entityName, Object entity)
			throws DataAccessException {
		hibernateTemplate.update(entityName, entity);
	}

	public void update(String entityName, Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.update(entityName, entity, lockMode);
	}

	public int bulkUpdate(String queryString) throws DataAccessException {
		return hibernateTemplate.bulkUpdate(queryString);
	}

	public int bulkUpdate(String queryString, Object value)
			throws DataAccessException {
		return hibernateTemplate.bulkUpdate(queryString, value);
	}

	public int bulkUpdate(String queryString, Object[] values)
			throws DataAccessException {
		return hibernateTemplate.bulkUpdate(queryString, values);
	}

	public void clear() throws DataAccessException {
		hibernateTemplate.clear();
	}

	@SuppressWarnings("unchecked")
	public void closeIterator(Iterator it) throws DataAccessException {
		hibernateTemplate.closeIterator(it);
	}

	public boolean contains(Object entity) throws DataAccessException {
		return hibernateTemplate.contains(entity);
	}

	public void delete(Object entity) throws DataAccessException {
		hibernateTemplate.delete(entity);
	}

	public void delete(Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.delete(entity, lockMode);
	}

	public void delete(String entityName, Object entity)
			throws DataAccessException {
		hibernateTemplate.delete(entityName, entity);
	}

	public void delete(String entityName, Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.delete(entityName, entity, lockMode);
	}

	@SuppressWarnings("unchecked")
	public void deleteAll(Collection entities) throws DataAccessException {
		hibernateTemplate.deleteAll(entities);
	}

	public void flush() throws DataAccessException {
		hibernateTemplate.flush();
	}

	public Filter enableFilter(String filterName) throws IllegalStateException {
		return hibernateTemplate.enableFilter(filterName);
	}

	public void evict(Object entity) throws DataAccessException {
		hibernateTemplate.evict(entity);
	}

	@SuppressWarnings("unchecked")
	public List executeFind(HibernateCallback action)
			throws DataAccessException {
		return hibernateTemplate.executeFind(action);
	}

	public Object executeWithNativeSession(HibernateCallback action)
			throws DataAccessException {
		return hibernateTemplate.executeWithNativeSession(action);
	}

	public Object executeWithNewSession(HibernateCallback action)
			throws DataAccessException {
		return hibernateTemplate.executeWithNewSession(action);
	}

	@SuppressWarnings("unchecked")
	public List find(String queryString) throws DataAccessException {
		return hibernateTemplate.find(queryString);
	}

	@SuppressWarnings("unchecked")
	public List find(String queryString, Object value)
			throws DataAccessException {
		return hibernateTemplate.find(queryString, value);
	}

	@SuppressWarnings("unchecked")
	public List find(String queryString, Object[] values)
			throws DataAccessException {
		return hibernateTemplate.find(queryString, values);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedParam(String queryString, String paramName,
			Object value) throws DataAccessException {
		return hibernateTemplate
				.findByNamedParam(queryString, paramName, value);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedParam(String queryString, String[] paramNames,
			Object[] values) throws DataAccessException {
		return hibernateTemplate.findByNamedParam(queryString, paramNames,
				values);
	}

	@SuppressWarnings("unchecked")
	public List findByValueBean(String queryString, Object valueBean)
			throws DataAccessException {
		return hibernateTemplate.findByValueBean(queryString, valueBean);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedQuery(String queryName) throws DataAccessException {
		return hibernateTemplate.findByNamedQuery(queryName);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedQuery(String queryName, Object value)
			throws DataAccessException {
		return hibernateTemplate.findByNamedQuery(queryName, value);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedQuery(String queryName, Object[] values)
			throws DataAccessException {
		return hibernateTemplate.findByNamedQuery(queryName, values);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedQueryAndNamedParam(String queryName,
			String paramName, Object value) throws DataAccessException {
		return hibernateTemplate.findByNamedQueryAndNamedParam(queryName,
				paramName, value);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedQueryAndNamedParam(String queryName,
			String[] paramNames, Object[] values) throws DataAccessException {
		return hibernateTemplate.findByNamedQueryAndNamedParam(queryName,
				paramNames, values);
	}

	@SuppressWarnings("unchecked")
	public List findByNamedQueryAndValueBean(String queryName, Object valueBean)
			throws DataAccessException {
		return hibernateTemplate.findByNamedQueryAndValueBean(queryName,
				valueBean);

	}

	@SuppressWarnings("unchecked")
	public List findByCriteria(DetachedCriteria criteria)
			throws DataAccessException {
		return hibernateTemplate.findByCriteria(criteria);
	}

	@SuppressWarnings("unchecked")
	public List findByCriteria(DetachedCriteria criteria, int firstResult,
			int maxResults) throws DataAccessException {
		return hibernateTemplate.findByCriteria(criteria, firstResult,
				maxResults);
	}

	@SuppressWarnings("unchecked")
	public List findByExample(Object exampleEntity) throws DataAccessException {
		return hibernateTemplate.findByExample(exampleEntity);
	}

	@SuppressWarnings("unchecked")
	public List findByExample(String entityName, Object exampleEntity)
			throws DataAccessException {
		return hibernateTemplate.findByExample(entityName, exampleEntity);
	}

	@SuppressWarnings("unchecked")
	public List findByExample(Object exampleEntity, int firstResult,
			int maxResults) throws DataAccessException {
		return hibernateTemplate.findByExample(exampleEntity, firstResult,
				maxResults);
	}

	@SuppressWarnings("unchecked")
	public List findByExample(String entityName, Object exampleEntity,
			int firstResult, int maxResults) throws DataAccessException {
		return hibernateTemplate.findByExample(entityName, exampleEntity,
				firstResult, maxResults);
	}

	@SuppressWarnings("unchecked")
	public Iterator iterate(String queryString) throws DataAccessException {
		return hibernateTemplate.iterate(queryString);
	}

	@SuppressWarnings("unchecked")
	public Iterator iterate(String queryString, Object value)
			throws DataAccessException {
		return hibernateTemplate.iterate(queryString, value);
	}

	@SuppressWarnings("unchecked")
	public Iterator iterate(String queryString, Object[] values)
			throws DataAccessException {
		return hibernateTemplate.iterate(queryString, values);
	}

	@SuppressWarnings("unchecked")
	public Object get(Class entityClass, Serializable id)
			throws DataAccessException {
		return hibernateTemplate.get(entityClass, id);
	}

	@SuppressWarnings("unchecked")
	public Object get(Class entityClass, Serializable id, LockMode lockMode)
			throws DataAccessException {
		return hibernateTemplate.get(entityClass, id, lockMode);
	}

	public Object get(String entityName, Serializable id)
			throws DataAccessException {
		return hibernateTemplate.get(entityName, id);
	}

	public Object get(String entityName, Serializable id, LockMode lockMode)
			throws DataAccessException {
		return hibernateTemplate.get(entityName, id, lockMode);
	}

	@SuppressWarnings("unchecked")
	public Object load(Class entityClass, Serializable id)
			throws DataAccessException {
		return hibernateTemplate.load(entityClass, id);
	}

	@SuppressWarnings("unchecked")
	public Object load(Class entityClass, Serializable id, LockMode lockMode)
			throws DataAccessException {
		return hibernateTemplate.load(entityClass, id, lockMode);
	}

	public Object load(String entityName, Serializable id)
			throws DataAccessException {
		return hibernateTemplate.load(entityName, id);
	}

	public Object load(String entityName, Serializable id, LockMode lockMode)
			throws DataAccessException {
		return hibernateTemplate.load(entityName, id, lockMode);
	}

	@SuppressWarnings("unchecked")
	public List loadAll(Class entityClass) throws DataAccessException {
		return hibernateTemplate.loadAll(entityClass);
	}

	public void load(Object entity, Serializable id) throws DataAccessException {
		hibernateTemplate.load(entity, id);
	}

	public void refresh(Object entity) throws DataAccessException {
		hibernateTemplate.refresh(entity);
	}

	public void refresh(Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.refresh(entity, lockMode);
	}

	public int getFetchSize() {
		return hibernateTemplate.getFetchSize();
	}

	public void setMaxResults(int maxResults) {
		hibernateTemplate.setMaxResults(maxResults);
	}

	public int getMaxResults() {
		return hibernateTemplate.getMaxResults();
	}

	public String getQueryCacheRegion() {
		return hibernateTemplate.getQueryCacheRegion();
	}

	public void initialize(Object proxy) throws DataAccessException {
		hibernateTemplate.initialize(proxy);
	}

	public boolean isAllowCreate() {
		return hibernateTemplate.isAllowCreate();
	}

	public boolean isAlwaysUseNewSession() {
		return hibernateTemplate.isAlwaysUseNewSession();
	}

	public boolean isCacheQueries() {
		return hibernateTemplate.isCacheQueries();
	}

	public boolean isCheckWriteOperations() {
		return hibernateTemplate.isCheckWriteOperations();
	}

	public boolean isExposeNativeSession() {
		return hibernateTemplate.isExposeNativeSession();
	}

	public void lock(Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.lock(entity, lockMode);
	}

	public void lock(String entityName, Object entity, LockMode lockMode)
			throws DataAccessException {
		hibernateTemplate.lock(entityName, entity, lockMode);
	}

	public Object merge(Object entity) throws DataAccessException {
		return hibernateTemplate.merge(entity);
	}

	public Object merge(String entityName, Object entity)
			throws DataAccessException {
		return hibernateTemplate.merge(entityName, entity);
	}

	public void persist(Object entity) throws DataAccessException {
		hibernateTemplate.persist(entity);
	}

	public void persist(String entityName, Object entity)
			throws DataAccessException {
		hibernateTemplate.persist(entityName, entity);
	}

	public void replicate(Object entity, ReplicationMode replicationMode)
			throws DataAccessException {
		hibernateTemplate.replicate(entity, replicationMode);
	}

	public void replicate(String entityName, Object entity,
			ReplicationMode replicationMode) throws DataAccessException {
		hibernateTemplate.replicate(entityName, entity, replicationMode);
	}

	public void setAllowCreate(boolean allowCreate) {
		hibernateTemplate.setAllowCreate(allowCreate);
	}

	public void setAlwaysUseNewSession(boolean alwaysUseNewSession) {
		hibernateTemplate.setAlwaysUseNewSession(alwaysUseNewSession);
	}

	public void setCacheQueries(boolean cacheQueries) {
		hibernateTemplate.setCacheQueries(cacheQueries);
	}

	public void setCheckWriteOperations(boolean checkWriteOperations) {
		hibernateTemplate.setCheckWriteOperations(checkWriteOperations);
	}

	public void setExposeNativeSession(boolean exposeNativeSession) {
		hibernateTemplate.setExposeNativeSession(exposeNativeSession);
	}

	public void setQueryCacheRegion(String queryCacheRegion) {
		hibernateTemplate.setQueryCacheRegion(queryCacheRegion);
	}

	public Object executeHibernateCallback(HibernateCallback hibernateCallback)
			throws DataAccessException {
		return hibernateTemplate.execute(hibernateCallback);
	}

}
